/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ntb.controllers;

import com.ntb.common.SecuredAction;
import com.ntb.controllers.forms.ContactListingForm;
import com.ntb.entities.Contact;
import com.ntb.models.ContactDAO;
import com.ntb.models.impl.ContactDAOImpl;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author Thinh Hung
 */
public class ContactAction extends SecuredAction {

    @Override
    public ActionForward ntbExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
        List<String> errorMessages = new ArrayList();
        List<String> successMessages = new ArrayList();
        ActionForward forward = mapping.getInputForward();
        ContactListingForm contactListingForm = (ContactListingForm) form;
        ContactDAO contactDao = new ContactDAOImpl();
        
        Contact contact = contactDao.getRow(contactListingForm.getContactID());
        if (contact == null) {
            errorMessages.add("Contact not found!");
            forward = mapping.findForward("contactListing");
        } else {
            contactDao.updateStatus(contact.getContactID());
            request.setAttribute("contact", contact);
        }
                
        request.setAttribute("errorMessages", errorMessages);
        request.setAttribute("successMessages", successMessages);
        return forward;
    }
}
